const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    cur: 0,
    selecthd: [],
    hdArr: [],
    theme: app.theme,
    supplyChannel: app.supplyChannel,
    windowWidth:app.globalData.windowWidth,
  },
  // attached() {
  //   this.init();
  // },
  /**
 * 组件的方法列表
   */
  methods: {
    init() {
      if (app.supplyChannel == 2) {
        let arr = [
          {
            id: 1,
            type: "all",
            name: app.activityName,
            description: app.activityDesc
          }, {
            id: 2,
            type: "hot",
            name: app.activityName2,
            description: app.activityDesc2
          }
        ];
        this.setData({
          theme: app.theme,
          supplyChannel: app.supplyChannel,
          hdArr:arr
        },()=>{
          this.gethdAll();
        })
      }else if(app.supplyChannel == 1){
        let arr = [
          {
            id: 1,
            type: "all",
            name: app.dfActivityName,
            description: app.dfActivityDesc
          }, {
            id: 2,
            type: "hot",
            name: app.dfActivityName2,
            description: app.dfActivityDesc2
          }
        ];
        this.setData({
          theme: app.theme,
          windowWidth:app.globalData.windowWidth,
          supplyChannel: app.supplyChannel,
          hdArr:arr
        },()=>{
          this.gethdAll();
        })
      }
    },
    // 活动专区
    gethdAll() {
      let that = this;
      let shop = app.functions.getLocalStorage("shop");
      let params = {
        supplyChannel: app.supplyChannel,
        centreId: shop.centreId
      };
      that.setData({
        theme: app.theme,
        selecthd: []
      })
      app.api.hdAll(params, (response) => {
        that.setData({
          selecthd: that.data.hdArr.concat(response.data),
          cur: 0
        }, () => {

        })
      }, (error) => {
        // console.info("活动专区api错误");
      })
    },
    tocurrent(e) {
      let item = e.currentTarget.dataset.item;
      let index = e.currentTarget.dataset.index;
      //每个tab选项宽度占1/3
      var singleNavWidth = this.data.windowWidth / 3;

      this.setData({
        cur: index,
        navScrollLeft: (index - 2) * singleNavWidth
      }, () => {
        let pages = getCurrentPages(); //获取加载的页面
        let currentPage = pages[pages.length - 1]; //获取当前页面的对象
        let url = currentPage.route;//当前页面url
        app.cache[url].getSwitchProducts(index, item);
      })


    }
  }
})
